package com.gms.tool;

import org.json.JSONException;
import org.json.JSONWriter;

import com.gms.server.model.City;
import com.gms.server.model.User;

/**
 * Containt only an static method.
 * @author JBromo
 *
 */
public class ModelToJsonFormat {
	
	/**
	 * This method take an object user and parset it with JsonWriter
	 * @param user : User to parse an json format
	 * @param jsonWriter : Writer to use for parsins
	 * @throws JSONException
	 */
	
	public static void userToJson(User user, JSONWriter jsonWriter) throws JSONException
	{
		jsonWriter.object();
		jsonWriter.key("loginStatus").value("yes");
		jsonWriter.key("username").value(user.getUsername());
		jsonWriter.key("userpassword").value(user.getPassword());
		jsonWriter.endObject();
	}

	public static void cityToJson(City city, JSONWriter jsonWriter) throws JSONException
	{
		jsonWriter.object();
		jsonWriter.key("loginStatus").value("yes");
		jsonWriter.key("cityName").value(city.getName());
		jsonWriter.key("cityPopulation").value(city.getPopulation());
		jsonWriter.endObject();
	}

}
